package com.warrior.superdata.enums;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @ClassName: Method.java
 * @date: 2022/2/23 17:08
 * @author xujian
 */
public enum DatasourceType {

    /*MYSQL(0, "MYSQL"),
    HIVE(1, "HIVE"),
    ES(3, "ES"),
    KAFKA(4, "KAFKA"),
    ORCALE(5, "ORCALE");*/

    MYSQL(1, "MYSQL"),
    ES(2, "ES");

    private Integer type;

    private String name;

    DatasourceType(Integer type, String name) {
        this.type = type;
        this.name = name;
    }

    public static Integer getTypeByName(String name) {
        DatasourceType[] values = DatasourceType.values();
        for (DatasourceType item : values) {
            if (item.name.equals(name)) {
                return item.type;
            }
        }
        return null;
    }

    public static String getNameByType(Integer type) {
        DatasourceType[] values = DatasourceType.values();
        for (DatasourceType item : values) {
            if (item.type.equals(type)) {
                return item.name;
            }
        }
        return null;
    }

    private static List<Map<String, Object>> LIST_RESULT = new ArrayList<>();

    public static List<Map<String, Object>> getList() {
        if (CollectionUtils.isEmpty(LIST_RESULT)) {
            DatasourceType[] values = DatasourceType.values();
            for (DatasourceType value : values) {
                Map<String, Object> map = new HashMap<>();
                map.put("type", value.type);
                map.put("name", value.name);
                LIST_RESULT.add(map);
            }
        }
        return LIST_RESULT;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
